﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace Clancy.Data
{
    public abstract class BaseDataContainer
    {
        private readonly Dictionary<string, object> m_Data = new Dictionary<string, object>();

        public event PropertyChangedEventHandler PropertyChanged;

        protected object GetProperty(string id, object defaultValue)
        {
            if (m_Data.ContainsKey(id))
                return m_Data[id];
            return defaultValue;
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        protected void SetProperty(string id, object val)
        {
            m_Data[id] = val;
            OnPropertyChanged(id);
        }
    }
}
